﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;

namespace SharpSqlAnalyzer.util
{
	// Token: 0x02000075 RID: 117
	internal class functionLoader
	{
		// Token: 0x060002D5 RID: 725 RVA: 0x002F8884 File Offset: 0x002F6A84
		private static void loadFunctionList(EDbVendor vendor)
		{
			if (!functionLoader.functionMap.ContainsKey(vendor))
			{
				string text = null;
				switch (vendor)
				{
				case EDbVendor.dbvaccess:
					text = "access";
					break;
				case EDbVendor.dbvdb2:
					text = "db2";
					break;
				case EDbVendor.dbvfirebird:
					text = "firebird";
					break;
				case EDbVendor.dbvgeneric:
					text = "generic";
					break;
				case EDbVendor.dbvgreenplum:
					text = "greenplum";
					break;
				case EDbVendor.dbvhive:
					text = "hive";
					break;
				case EDbVendor.dbvinformix:
					text = "informix";
					break;
				case EDbVendor.dbvmdx:
					text = "mdx";
					break;
				case EDbVendor.dbvmysql:
					text = "mysql";
					break;
				case EDbVendor.dbvmssql:
					text = "mssql";
					break;
				case EDbVendor.dbvnetezza:
					text = "netezza";
					break;
				case EDbVendor.dbvoracle:
					text = "oracle";
					break;
				case EDbVendor.dbvpostgresql:
					text = "postgresql";
					break;
				case EDbVendor.dbvsybase:
					text = "sybase";
					break;
				case EDbVendor.dbvteradata:
					text = "teradata";
					break;
				case EDbVendor.dbvsnowflake:
					text = "snowflake";
					break;
				}
				try
				{
					Assembly executingAssembly = Assembly.GetExecutingAssembly();
					Dictionary<string, string> dictionary = new Dictionary<string, string>();
					bool flag = false;
					foreach (string text2 in executingAssembly.GetManifestResourceNames())
					{
						if (text2.EndsWith(text + "_function.properties"))
						{
							using (StreamReader streamReader = new StreamReader(executingAssembly.GetManifestResourceStream(text2), Encoding.UTF8, true, 1024))
							{
								string text3;
								while ((text3 = streamReader.ReadLine()) != null)
								{
									if (text3.Trim().Length != 0 && !text3.Trim().StartsWith("#") && text3.Trim().IndexOf('=') != -1)
									{
										dictionary.Add(text3.Split(new char[]
										{
											'='
										})[0], string.Join("=", CollectionUtil<string>.RemoveAt(new List<string>(text3.Split(new char[]
										{
											'='
										})), 0).ToArray()));
									}
								}
							}
							functionLoader.functionMap[vendor] = dictionary;
							flag = true;
							break;
						}
					}
					if (!flag)
					{
						Console.WriteLine("Doesn't implement " + vendor.ToString());
						functionLoader.functionMap[vendor] = null;
					}
				}
				catch (IOException ex)
				{
					Console.WriteLine("Load " + text + " failed.");
					Console.WriteLine(ex.ToString());
					functionLoader.functionMap[vendor] = null;
				}
			}
		}

		// Token: 0x060002D6 RID: 726 RVA: 0x002F8B18 File Offset: 0x002F6D18
		public static IDictionary<string, string> getFunctionList(EDbVendor vendor)
		{
			functionLoader.loadFunctionList(vendor);
			return functionLoader.functionMap[vendor];
		}

		// Token: 0x04001084 RID: 4228
		private static IDictionary<EDbVendor, IDictionary<string, string>> functionMap = new Dictionary<EDbVendor, IDictionary<string, string>>();
	}
}
